# -*- coding:utf-8

import urllib
import urllib2

#https://movie.douban.com/j/new_search_subjects
url = 'https://movie.douban.com/j/new_search_subjects?sort=T&range=0,10'

#要传递的post方式嗯对数据，有可能会有多组数据
submit_data = {
    'start':20,
    'tags':'科幻'
}
#编码
data = urllib.urlencode(submit_data)

#构造请求头，创建请求对象
headers = {
    "Accept" : "application/json, text/plain, */*",
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.7 Safari/537.36",
    "Accept-Language" : "zh-CN,zh;q=0.8"
}

request = urllib2.Request(url,data,headers)

#发送请求，获取服务器响应数据
response = urllib2.urlopen(request)

#获取爬取到的数据
content = response.read()

#保存数据
with open('movies.json','w') as f:
    f.write(content)

